﻿// This Class has been taken from Droid Explorer <http://de.codeplex.com/license>
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace DroidManager.Android.Aapt
{
    /// <summary>
    /// 
    /// </summary>
    internal class AaptPermissionsCommandResult : CommandResult
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AaptPermissionsCommandResult"/> class.
        /// </summary>
        /// <param name="data">The data.</param>
        internal AaptPermissionsCommandResult(string data)
            : base()
        {
            Permissions = new List<string>();
            ProcessData(data);
        }

        /// <summary>
        /// Gets or sets the permissions.
        /// </summary>
        /// <value>The permissions.</value>
        internal List<string> Permissions { get; private set; }

        /// <summary>
        /// Gets or sets the local apk.
        /// </summary>
        /// <value>The local apk.</value>
        internal string LocalApk { get; set; }

        /// <summary>
        /// Processes the data.
        /// </summary>
        /// <param name="data">The data.</param>
        protected override void ProcessData(string data)
        {
            base.ProcessData(data);
            Regex regex = new Regex(@"uses-permission:\s(.*)",
                                    RegexOptions.Compiled | RegexOptions.IgnoreCase |
                                    RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);
            Match m = regex.Match(data);
            while (m.Success)
            {
                Permissions.Add(m.Groups[1].Value);
                m = m.NextMatch();
            }
        }
    }
}